function hfile2 = aft_CopyObject(hfile)
% AFT::CopyObject  - copy object to new
%
% FORMAT:       copied = obj.CopyObject;
%
% No input fields
%
% Output fields:
%
%       copied      BVQXfile object with own storage in bvqxcont
%
% TYPES: ALL

% Version:  v0.8a
% Build:    9102122
% Date:     Oct-21 2009, 10:19 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% check arguments
if nargin < 1 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, true)
    error( ...
        'BVQXfile:BadArguments', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end

% create same type of object
try
    hfile2 = BVQXfile(0, 'copyobject', hfile.L);
catch
    rethrow(lasterror);
end
